﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;


namespace FYPHP
{
    public partial class MemberChangePassword : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {

            SqlCommand cmdUpdatePass;

            conn.Open();

           

        
                cmdUpdatePass = new SqlCommand("Update Users SET password=@Password where u_id=@UID",conn);
                cmdUpdatePass.Parameters.AddWithValue("@Password",txtNew.Text);
                cmdUpdatePass.Parameters.AddWithValue("@UID",Session["ID"].ToString());
                cmdUpdatePass.ExecuteNonQuery();

           
          

            conn.Close();

            MessageBox("Password Change Successfully!!!");
            Redirect("ViewMemberProfile.aspx");

        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            
            txtNew.Text = "";
            txtRetype.Text = "";
        }

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }

        private void Redirect(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language=\"javascript\">window.location='" + msg + "';</script>";
            Page.Controls.Add(lbl);
        }
    }
}